﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Developer.Core.FrameWork.RedisExtensions.RedisSubscribeInit.InitMq
{
    public class HostedService : IHostedService, IDisposable
    {
        private readonly ILogger _logger;
        private readonly IServiceProvider _provider;
        private readonly IOptions<InitMqOption> _options;

        public HostedService(
          ILogger<HostedService> logger,
          IServiceProvider provider,
          IOptions<InitMqOption> options)
        {
            this._logger = (ILogger)logger;
            this._provider = provider;
            this._options = options;
        }

        public Task StartAsync(CancellationToken cancellationToken)
        { 
            this._logger.LogInformation("Redis发布订阅程序启动");
            new InitMqCore().FindInterfaceTypes(this._provider, this._options.Value);
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            this._logger.LogInformation("结束");
            return Task.CompletedTask;
        }

        public void Dispose()
        {
        }
    }
}
